/*
 * Copyright (c) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef KALMAN_TRACKING_H
#define KALMAN_TRACKING_H

#include <iostream>
#include <opencv2/opencv.hpp>
#include "svp_nnie_application.h"

#if __cplusplus
extern "C" {
#endif

class KalmanTracking {
public:
    RectBox KalmanTrackingTarget(SAMPLE_IVE_KCF_S *stKcfInfo, SVP_NNIE_YOLOV5_BBOX_S *nodes, HI_FLOAT match_thresh, HI_BOOL *isMatch);
private:
    void init(RectBox targetBox);
    void max_iou_match(SVP_NNIE_YOLOV5_BBOX_S *nodes, HI_BOOL *is_match, HI_FLOAT match_threshold,
            cv::Mat s_statePost, cv::Mat &s_measurement);
    cv::Mat statePre;
    cv::Mat statePost;

    cv::Mat transitionMatrix;
    cv::Mat measurementMatrix;
    cv::Mat processNoiseCov;
    cv::Mat measurementNoiseCov;

    cv::Mat errorCovPre;
    cv::Mat errorCovPost;

    cv::Mat measurement;

    cv::Mat gain;

    cv::Mat temp1;
    cv::Mat temp2;
    cv::Mat temp3;
    cv::Mat temp4;
    cv::Mat temp5;
    cv::Mat temp6;
};

#ifdef __cplusplus
}
#endif
#endif